package com.company.project.configurer;

import org.springframework.core.Ordered;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet;

public class DefaultServletContainerInitializer implements WebApplicationInitializer,Ordered{
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {

        CharacterEncodingFilter encodingFilter=new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");
        encodingFilter.setForceEncoding(true);
        javax.servlet.FilterRegistration.Dynamic dynamic=
                servletContext.addFilter("encodingFilter",encodingFilter);
        dynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),false,"/*");

    }

    @Override
    public int getOrder() {
        return HIGHEST_PRECEDENCE;
    }
}
